// ==UserScript==
// @name       A Friend On My Homepage
// @namespace  http://kiokucreations.zzl.org/
// @version    0.3
// @description A friend to help you out.
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @require     http://code.jquery.com/ui/1.10.2/jquery-ui.js
// @require		http://kiokucreations.zzl.org/scriptorz.js
// @require		https://raw.github.com/carhartl/jquery-cookie/master/jquery.cookie.js
// @match     http://www.feedly.com/*
// @copyright  2012+, Kio @ KiokuCreations
// ==/UserScript==

setTimeout(function(){
    var InjectMe="";
    InjectMe += "<img id=\"magic\" src=\"https:\/\/dl.dropboxusercontent.com\/u\/10896585\/kona.png\" alt=\"ERROR\" style=\"position:fixed; left:0px; bottom:-10px; z-index: 999;\"><\/img>";
    InjectMe += "<div id=\"magic-popup\" title=\"Control Panel\" style=\"z-index: 5; overflow:hidden !important;\"><iframe src=\"http:\/\/kiokucreations.zzl.org\/mini.html\" width=\"100%\" height=\"88px\"><\/iframe>";
    InjectMe += "<div><p id=\"magic-hideall\" style=\"float:left;\">Hide All!<\/p><p id=\"magic-popall\" style=\"float:right;\">Pop All!<\/p><\/div><div id=\"opacity-slider\"><\/div><\/div>";
    
    document.getElementById("footnoteBar").innerHTML = InjectMe;
    
    $("head").append($("<link rel=\"stylesheet\" href=\"http:\/\/code.jquery.com\/ui\/1.10.2\/themes\/smoothness\/jquery-ui.css\" \/>"));
    $("head").append($("<link rel=\"stylesheet\" href=\"http:\/\/kioku-userscript-files.googlecode.com\/svn\/trunk\/extra.css\" \/>"));
    
    $("body").css("background-image", "url('http://kioku-userscript-files.googlecode.com/svn/trunk/yande.re%20251847%20beek%20gumi%20hatsune_miku%20kagamine_len%20kagamine_rin%20kaito%20megurine_luka%20thighhighs%20vocaloid%20wings.jpg')");
    $("body").css("background-repeat", "no-repeat");
    $("body").css("background-attachment", "fixed");
    
    // SAVED COOKIES //
    var cAlpha = $.cookie("c_alpha");

    if( !cAlpha ){
        $.cookie("c_alpha", 0.89);
        cAlpha = 0.89
    }
    // END COOKIES //
    
    $("#fusionModule_part").css("opacity", "0");
    $("#fusionModule_part").remove();
    $("#sponsorsModule_part").css("opacity", "0");
    $("#sponsorsModule_part").remove();
    
    $("#feedlyPart0").css("background-color", "rgba(255,255,255," + cAlpha + ")");
    $("#feedlyPart0").css("border-color", "rgba(255,255,255," + cAlpha + ")");
    $("#feedlyTabsHolder").css("background-color", "rgba(255,255,255," + cAlpha + ")");
    
    $( "#opacity-slider" ).slider({
      range: "min",
      value: (cAlpha * 100),
      min: 1,
      max: 100,
      slide: function( event, ui ) {
        $("#feedlyPart0").css("background-color", "rgba(255,255,255," + (ui.value / 100) + ")");
        $("#feedlyPart0").css("border-color", "rgba(255,255,255," + (ui.value / 100) + ")");
        $("#feedlyTabsHolder").css("background-color", "rgba(255,255,255," + (ui.value / 100) + ")");
        $.cookie("c_alpha", (ui.value / 100));
      }
    });
    
    $("#magic-hideall").click(function(){
        $("div:visible").fadeTo("slow", 0.1);
        setTimeout(function(){ $("div:visible").fadeTo("slow", 1); }, 5000)
    })
    $("#magic-popall").click(function(){
        $("#feedlyPart0").css("overflow", "scroll");
        $("#feedlyPart0").dialog({
            close: function (event, ui) {
                location.reload();
            },
            minHeight: 200,
            height: 200
        });
        
        $("#feedlyTabsHolder").css("position", "fixed");
        $("#feedlyTabsHolder").css("left", "0px");
        $("#feedlyTabsHolder").css("top", "0px");
        $("#feedlyTabsHolder").css("background-color", "rgba(255,255,255,0.79)");
    })
    
    $("#magic").click(function(){
        $( "#magic-popup" ).dialog({
            open: function (event, ui) {
                document.getElementById("feedlyPart0").style.zIndex = -1;
            },
            close: function (event, ui) {
                document.getElementById("feedlyPart0").style.zIndex = 1;
            },
            resizable: false,
    		minHeight: 166,
            height: 166,
            minWidth: 264,
            width: 264,
            modal: false,
            zIndex: 9999,
            stack: false
        });
    });
    
    $(function() { $( "#magic-popup" ).dialog(); $( "#magic-popup" ).dialog('close'); });
},500);